<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改企业收费记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:80%;height:600px;margin:15px auto;overflow:auto;" id="aaa">
    <form class="layui-form" action="">
        <input type="hidden" id="id" name="id" class="input-text">
        <!--<input type="hidden" id="createtime" name="createtime" class="input-text">-->
        <input type="hidden" id="qyID" name="qyID" class="input-text">
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">缴费企业</label>
            <div class="layui-input-block">
                <input type="text" id="qyName" name="qyName" readonly lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">金额</label>
            <div class="layui-input-block">
                <input type="text" id="money" name="money" required  lay-verify="required|double" placeholder="请输入金额" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!--<div class="layui-form-item" style="">-->
            <!--<label class="layui-form-label">缴费时间</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<input type="text" name="jfTime" id="jftime" lay-verify="required" autocomplete="off" placeholder="请输入缴费时间" class="layui-input">-->
            <!--</div>-->
            <!--&lt;!&ndash;<div class="layui-form-mid layui-word-aux">辅助文字</div>&ndash;&gt;-->
        <!--</div>-->
        <div class="layui-form-inline">
            <label class="layui-form-label">时间段</label>
            <div class="layui-input-inline">
                <input type="text" id="start_time" name="start_time" lay-verify="required" autocomplete="off" placeholder="请输入开始时间" class="layui-input">
            </div>
            <div style="display: inline;">至</div>
            <div class="layui-input-inline">
                <input type="text" id="end_time" name="end_time" lay-verify="required" autocomplete="off" placeholder="请输入结束时间" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-row layui-col-xs12" style="margin-top: 20px">
            <div class="layui-col-xs10 layui-col-xs-offset2">
                <button class="layui-btn" id="addWuye" lay-submit lay-filter="addWuye">立即修改</button>
                <button type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="../../js/layui/layui.js"></script>
<script src="../../js/layui/layui.all.js"></script>
<script src="../../js/token.js"></script>
<script src="../../js/config.js"></script>

<script>
    //遍历员工下选框
    // $.ajax({
    //     url: "/staff/selectallstaff"
    //     , type: "POST"
    //     , contentType: 'application/json'
    //     , data: {'status': 1}
    //     , success: function (data) {
    //         $.each(data.data, function (index, item) {
    //             $('#sta').append(new Option(item.name, item.id));// 下拉菜单里添加元素
    //         });
    //         layui.form.render("select");
    //     }
    // });

    //url 传参
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var a = decodeURI(window.location.search);
        var r = a.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
        if(r!=null)return  unescape(r[2]); return null;
    }

    window.onload = function(){
        var form = layui.form;
        $("input[name='id']").val(GetQueryString("id"));
        $("input[name='money']").val(GetQueryString("money"));
        $("input[name='qyID']").val(GetQueryString("qyID"));
        // $("input[name='createtime']").val(GetQueryString("createTime"));
        $("input[name='qyName']").val(GetQueryString("qyName"));
        $("input[name='start_time']").val(GetQueryString("ksTime"));
        $("input[name='end_time']").val(GetQueryString("jsTime"));
        //下拉列表选中
        // $('#eee').text(GetQueryString("staffName"));
        // $('#eee').val(GetQueryString("staffID"));
        form.render();
    }

    layui.use(['form' , 'jquery'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //自定义验证规则  检测是否为数字
        form.verify({
            double: function(value){
                if(/^\d+$/.test(value)==false && /^\d+\.\d+$/.test(value)==false)
                {
                    return '你输入的不是数字';
                }
            }
        });

        //修改操作
        form.on('submit(addWuye)',function(data){
            data.field.ksTime=$("#start_time").val();
            data.field.jsTime=$("#end_time").val();
            data.field.qyID=$("#qyID").val();
            data.field.id = $("#id").val();
            var money = $("#money").val();
            if (money.length > 20) {
                layer.msg('金额最大长度不能超过20位！');
                return false;
            }
            // data.field.createTime = $("#createtime").val();
            $.ajax({
                url:HOST+"qiyeShoufei/updQiyeShoufei"
                ,type:"POST"
                ,contentType: 'application/json'
                ,data:JSON.stringify(data.field)
                ,success:function (data) {
                    if(data.code==0){
                        layer.close(layer.index);
                        layer.msg('修改成功');
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭弹出层
                            parent.location.reload();//重新加载父页面表格
                        }, 2000);
                    }else if(data.code==1){
                        layer.msg("缴费失败");
                    }else{
                        layer.msg("拒绝访问");
                    }
                }
                ,error:function () {
                    console.log("ajax error");
                }
            });
            return false;
        });
    });
</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            trigger:'click',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });
        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'datetime',
            trigger:'click',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });
    });
</script>
</body>
</html>